<template>
    <div class="apiSearchContainer">
        <span class="inputLabel">角色编码</span>
        <el-input v-model="roleSearchData.roleCode" placeholder="角色编码" class="searchInfoInput"></el-input>

        <span class="inputLabel">角色名称</span>
        <el-input v-model="roleSearchData.roleName" placeholder="角色名称" class="searchInfoInput"></el-input>

        <el-button type="primary" icon="SearchOutlined" class="searchButtonClass" :loading="searchLoading" @click="queryUserInfo()">搜索</el-button>
        <el-button icon="RedoOutlined" @click="resetInput()">重置</el-button>
    </div>
</template>

<script name="RoleSearch" setup lang="ts">
import {roleInfoQuery} from "@/request/role";
import {computed, ref} from "vue";
import {useRoleInfoStore} from "@/stores/userInfo/roleInfo";

let searchLoading = ref(false);

let roleSearchData = computed(() => {return useRoleInfoStore().roleSearchData});

function queryUserInfo() {
    searchLoading.value = true
    roleInfoQuery(roleSearchData.value).then(res => {
        if (res["code"] === '200') {
            useRoleInfoStore().resetRoleDataList(res.data);
        }
        searchLoading.value = false
    }).catch(res => {
        searchLoading.value = false
    })
}

function resetInput() {
    let info = {
        roleCode: '',
        roleName: ''
    }
    useRoleInfoStore().resetRoleSearchData(info);
}
</script>

<style scoped lang="less">
.apiSearchContainer {
    width: 100%;
    height: 10%;
    .searchInfoInput {
        width: 15%;
        padding-left: 1%;
    }
    .inputLabel {
        padding-left: 1%;
        font-weight: 700;
        font-size: 15px;
        color: #606266;
    }
    .searchButtonClass {
        margin-left: 1%;
    }
}
</style>